﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;

namespace MillerApp.CommonLib.DataAccess
{
    /// <summary>
    /// 数据库访问接口
    /// </summary>
    public interface IDBHelper
    {
        int ExecuteNonQuery(string sql, IList<IDbDataParameter> parameters);
        int ExecuteNonQuery(string sql, IList<IDbDataParameter> parameters, CommandType commandType);
        IDataReader ExecuteReader(string sql, IList<IDbDataParameter> parameters);
        IDataReader ExecuteReader(string sql, IList<IDbDataParameter> parameters, CommandType commandType);
        DataTable ExecuteDataTable(string sql, IList<IDbDataParameter> parameters);
        DataTable ExecuteDataTable(string sql, IList<IDbDataParameter> parameters, CommandType commandType);
        Object ExecuteScalar(string sql, IList<IDbDataParameter> parameters);
        Object ExecuteScalar(string sql, IList<IDbDataParameter> parameters, CommandType commandType);
        DbCommand CreateDbCommand(string sql, IList<IDbDataParameter> parameters, CommandType commandType);
        List<T> GetDataListByCond<T>(string viewName, string conditions, string sortExpression, int pageIndex, int pageSize, out int recordCount, LoadFromReaderHanlder<T> hanlder);
        DataTable GetDataListByCond(string viewName,string fields, string conditions, string sortExpression, int pageIndex, int pageSize, out int recordCount);
        DataTable GetDataTableByCond(string viewName, string fields, string conditions, string sortExpression);
        IDbDataParameter GetDbDataParameter(string nativeType, string parameterName, object parameterValue);
    }

    /// <summary>
    /// 从DataReader中读取数据转化为实体
    /// </summary>
    /// <typeparam name="T">实体类型</typeparam>
    /// <param name="reader">DataReader对象</param>
    /// <param name="entity">返回的对象实体</param>
    public delegate void LoadFromReaderHanlder<T>(IDataReader reader, ref T entity);
}
